<!DOCTYPE html>
 <html>
 <head>
 	<title>day 1</title>
 </head>
 <body>
 <h1>Phone类的相关练习</h1>
 </body>
 </html>

<?php
header("Content-type:text/html;charset=utf-8");
class Phone{
	//下面是声明人的三个成员属性
	private $manufacturers;//成员属性名字
	private $color;//成员属性性别
	private $battery_capacity;
	private $screen_size;//成员属性年龄
	//下面是声明人的两个成员方法
	public function call(){
		echo"正在打电话。<br>";
		/*echo "我的名字：".$this->name."，年龄：".$this->age."，性别：".$this->sex."<br>";*/
	}
	public function message(){
		echo"正在发短信。<br>";
		/*echo $this->name."在走路<br>";*/
	}
	public function photo(){
		echo"正在照相。<br>";
		/*echo $this->name."在走路<br>";*/
	}
		public function getmanufacturers(){

		return $this->manufacturers;
	}
	public function __construct($manufacturers="",$color="黑色",
		$battery_capacity="2000",$screen_size="5.5")
	{
		$this->setmanufacturers($manufacturers);
		$this->setcolor($color);
		$this->setbattery_capacity($battery_capacity);
		$this->setscreen_size($screen_size);

	}
	function __destruct(){

		echo"再见".$this->manufacturers."<br>";

	}
	public function setmanufacturers($manufacturers){

		$this->manufacturers=$manufacturers;
	}
	public function setbattery_capacity($battery_capacity){
		if ($battery_capacity>0&&$battery_capacity<=10000) {
		$this->battery_capacity=$battery_capacity;
		}

		else
			echo"电池容量输入有误,修改失败！<br>";

	}
	public function setscreen_size($screen_size){
		if ($screen_size>0&&$screen_size<=6) {
		$this->screen_size=$screen_size;
		}

		else
			echo"屏幕尺寸输入有误,修改失败！<br>";

	}
		public function setcolor($color){
			return $this->color;
		

	}

}
//通过new关键字实例化Phone类的三个实例对象
$p1 = new Phone("苹果","黑色","2000","4.7");//通过类Phone创建第一个实例对象$Phone1
//$p1->name="aaa";错误的访问。不能访问私有的成员
$p2 = new Phone("三星","白色","1600","5.5");
$p3 = new Phone("小米","白色","1600","5.0");
$p1->setmanufacturers("华为<br>");
$p1->setbattery_capacity("100000");
$p1->setcolor("绿色");
echo $p1->getmanufacturers();
//下面三行是给$Phone1对象中属性初始化赋值
$p1->call();
$p2->message();
$p3->photo();
 ?>